package com.jx.db137.controller;

import com.jx.db137.common.R;
import com.jx.db137.entity.Menu;
import com.jx.db137.entity.Rolemenu;
import com.jx.db137.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jx
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:51
 */
@CrossOrigin(origins = "*")
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;
    @GetMapping("getMenusByUserId")
    public List<Menu> getMenusByUserId() {
        int userid=1;
        return menuService.getMenusByUserId(userid);
    }


    //查看菜单
    @GetMapping("menuList")
    public List<Menu> menuList(){
        return menuService.list();
    }
    //删除
    @GetMapping("deleteMenu")
    public int deleteMenu(@RequestParam("id") int id){
        return menuService.deleteById(id);
    }
    //添加
    @PostMapping("addMenu")
    public R addMenu(@RequestBody Menu menu){
        return new R().addData("menu",menuService.insert(menu));
    }
    //修改
    @PostMapping("updateMenu")
    public R updateMenu(@RequestBody Menu menu){
        return new R().addData("menu",menuService.updateById(menu));
    }

    @GetMapping("selectMenuName")
    public List<Menu> selectMenuName(@RequestParam("label") String label){
        return menuService.selectMenuName(label);
    }



}
